﻿using System;
using System.Web.Mvc;
using OpenIdPortableArea.Helpers;
using OpenIdPortableArea;

namespace MvcApplication1.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Register()
        {
            string id = Session["OpenIDClaimedIdentifier"] as string;

            if (string.IsNullOrEmpty(id))
                return RedirectToRoute("OpenId");

            ViewData["OpenIDClaimedIdentifier"] = id;
            ViewData["OpenIDClaimedEmail"] = Session["OpenIDClaimedEmail"];

            return View();
        }

        [HttpPost]
        public ActionResult Register(string displayname)
        {
            OpenIdHelpers.Login(displayname, "", new TimeSpan(0, 5, 0), true);

            return RedirectToAction("Welcome");
        }

        [Authorize]
        [HttpGet]
        public ActionResult Welcome()
        {
            return View();
        }
    }
}
